import type { RouteRecordRaw } from "vue-router";

import { asyncRoutes, constantRoutes } from "@/router/routes.ts";

const useRouterStore = defineStore("routerStore", {
  state: () => ({
    routes: [] as RouteRecordRaw[],
  }),

  getters: {
    getRoutes(): RouteRecordRaw[] {
      return this.routes;
    },
  },

  actions: {
    setRoutes() {
      const finallyRoutes = [...constantRoutes, ...asyncRoutes];
      this.routes = finallyRoutes;
      return [...asyncRoutes];
    },
  },
  persist: {
    key: "useRouterStore", //存储名称
    storage: sessionStorage, // 存储方式
    paths: ["asyncRoutes"],
  },
});

export default useRouterStore;
